package com.ict.ais.targetLocation.service.api.impl;


import org.springframework.stereotype.Service;

import com.ict.ais.targetLocation.facade.api.ITargetLocationService;
import com.ict.ais.targetLocation.facade.dto.PgParams;
import com.ict.ais.targetLocation.facade.model.targetLocation;
import com.ict.ais.targetLocation.service.dao.ItargetLocationDao;

import javax.annotation.Resource;
import java.util.List;

@Service("targetLocationService")
public class targetLocationService implements  ITargetLocationService{
    @Resource
    ItargetLocationDao itargetLocationDao;

    public int targetFuseLocation(String num,int type){
        try{
            switch (type){
                case 1:
                    return itargetLocationDao.countFuseMMSI(num);
                case 2:
                    return itargetLocationDao.countFuseCallSign(num);
                case 3:
                    return itargetLocationDao.countFuseID(num);
                case 4:
                    return itargetLocationDao.countFuseShipName(num);
                case 5:
                    return itargetLocationDao.countFuseIMO(num);
                case 0:
                    return itargetLocationDao.countFuseAll(num);
                default:
                    return 0;
            }
        }catch (Exception e){
            System.out.println("数据库操作失败："+e);
            return -1;
        }
    }

    public int targetOriginLocation(String num,int type){
        try{
            switch (type){
                case 1:
                    return itargetLocationDao.countOriginMMSI(num);
                case 2:
                    return itargetLocationDao.countOriginCallSign(num);
                case 3:
                    return itargetLocationDao.countOriginID(num);
                case 4:
                    return itargetLocationDao.countOriginShipName(num);
                case 5:
                    return itargetLocationDao.countOriginIMO(num);
                case 0:
                    return itargetLocationDao.countOriginAll(num);
                default:
                    return 0;
            }
        }catch (Exception e){
            System.out.println("数据库操作失败："+e);
            return -1;
        }
    }

    public List<targetLocation> pageFuseLocation(String num, int type,int pageId,int pageCount){
        PgParams pgParams =new PgParams();
        pgParams.setNum(num);
        //limit分页起始
        pgParams.setStartPage((pageId-1)*pageCount);
        //limit分页结束
        pgParams.setEndPage(pageCount);

        try{
            switch (type){
                case 1:
                    return itargetLocationDao.pageFuseMMSI(pgParams);
                case 2:
                    return itargetLocationDao.pageFuseCallSign(pgParams);
                case 3:
                    return itargetLocationDao.pageFuseID(pgParams);
                case 4:
                    return itargetLocationDao.pageFuseShipName(pgParams);
                case 5:
                    return itargetLocationDao.pageFuseIMO(pgParams);
                case 0:
                    return itargetLocationDao.pageFuseAll(pgParams);
                default:
                    return null;
            }
        }catch (Exception e){
            System.out.println("数据库操作失败："+e);
            return null;
        }
    }

    public List<targetLocation> pageOriginLocation(String num, int type,int pageId,int pageCount){
        PgParams pgParams =new PgParams();
        pgParams.setNum(num);
        //limit分页起始
        pgParams.setStartPage((pageId-1)*pageCount);
        //limit分页结束
        pgParams.setEndPage(pageCount);

        try{
            switch (type){
                case 1:
                    return itargetLocationDao.pageOriginMMSI(pgParams);
                case 2:
                    return itargetLocationDao.pageOriginCallSign(pgParams);
                case 3:
                    return itargetLocationDao.pageOriginID(pgParams);
                case 4:
                    return itargetLocationDao.pageOriginShipName(pgParams);
                case 5:
                    return itargetLocationDao.pageOriginIMO(pgParams);
                case 0:
                    return itargetLocationDao.pageOriginAll(pgParams);
                default:
                    return null;
            }
        }catch (Exception e){
            System.out.println("数据库操作失败："+e);
            return null;
        }
    }
}
